using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class HandleLobbyWindow : MonoBehaviour
{
    public TextMeshProUGUI txtCoin;//金币文本
    public TextMeshProUGUI txtHistory;//历史记录文本
    // //玩家名文本标签
    // public TextMeshProUGUI playerNameText;
    // //玩家头像图片
    // public Image playerAvatarImage;
    
    private GameRoot root;

    public void Init()
    {
        root = GameRoot.Instance;
        Debug.Log("Init Lobby Window");
        RefreshCoinData();
        RefreshHistoryData();
    }

    public void OnBtnStartClicked()
    {
        root.OpenFightWindow();//打开战斗界面
    }

    public void RefreshCoinData()
    {
        txtCoin.text = root.GetCoin().ToString();
    }
    
    public void RefreshHistoryData()
    {
        string mTime = root.GetTime();
        if (!mTime.Equals(""))
        {
            int mScore = root.GetScore();
            txtHistory.text = "最高积分：" + mScore + "分\n\n记录时间：" + mTime;
            txtHistory.alignment = TextAlignmentOptions.MidlineLeft;
        }
        else
        {
            txtHistory.text = "暂无数据"; //这里可以根据服务器返回的时间显示历史最高分
        }
    }

    public void OnBtnResetClicked()
    {
        PlayerPrefs.DeleteAll();
        root.OpenTipsWindow("数据清除完成");
    }
    
    // public void RefreshDataInfo()
    // {
    //     Debug.Log("Refresh Data Info");
    //     //刷新金币信息
    //     txtCoin.text = "1000";
    //     //刷新历史记录信息
    //     txtHistory.text = "1000";
    //     //刷新玩家名信息
    //     // playerNameText.text = "Player1";
    //     //刷新玩家头像信息
    //     // playerAvatarImage.sprite = Resources.Load<Sprite>("Avatar/player1");
    // }
}
